import request from '@/utils/request';

// 文章列表
export function fetchArticleList(params) {
  // 预留后端对接：return request({ url: '/api/blog/list', method: 'get', params });
  return Promise.resolve({
    data: {
      total: 42,
      items: Array.from({ length: params.pageSize || 10 }).map((_, i) => ({
        id: `${params.page}-${i}`,
        title: `示例文章标题 ${params.page}-${i}`,
        author: 'OJ用户',
        publishTime: '2025-01-01',
        readCount: Math.floor(Math.random() * 1000),
        likeCount: Math.floor(Math.random() * 200),
        summary: '这是一段文章摘要，用于展示列表中的预览内容。',
        tags: ['OJ', '算法', 'Vue'],
      })),
    },
  });
}

// 分类
export function fetchCategories() {
  return Promise.resolve({ data: [
    { id: 1, name: '算法', children: [{ id: 11, name: '动态规划' }, { id: 12, name: '图论' }] },
    { id: 2, name: '前端', children: [{ id: 21, name: 'Vue' }, { id: 22, name: 'CSS' }] },
    { id: 3, name: '后端', children: [{ id: 31, name: 'Java' }, { id: 32, name: '数据库' }] },
  ]});
}

export function fetchHotList() {
  return Promise.resolve({ data: Array.from({ length: 8 }).map((_, i) => ({ id: i + 1, title: `热门文章 ${i + 1}` })) });
}

export function fetchRecommendAuthors() {
  return Promise.resolve({ data: Array.from({ length: 5 }).map((_, i) => ({ id: i + 1, name: `作者${i + 1}`, desc: '擅长算法与前端', avatar: '' })) });
}

export function fetchTags() {
  return Promise.resolve({ data: [
    { id: 't1', name: 'OJ' }, { id: 't2', name: '算法' }, { id: 't3', name: 'Vue' }, { id: 't4', name: 'Java' },
  ]});
}

// 详情
export function fetchArticleDetail(id) {
  return Promise.resolve({ data: {
    id,
    title: `示例文章 ${id}`,
    author: { name: 'OJ用户', avatar: '' },
    publishTime: '2025-01-01',
    readCount: 123,
    likeCount: 45,
    tags: ['OJ', '算法'],
    content: `# 示例文章\n\n这是使用 Markdown 编写的示例文章。\n\n\`\`\`js\nconsole.log('代码高亮演示');\n\`\`\`\n\n更多内容...`,
  }});
}

export function fetchComments(articleId) {
  return Promise.resolve({ data: [
    { id: 'c1', user: { name: '评论者A', avatar: '' }, time: '2025-01-01 10:00', likeCount: 3, content: '写得很棒！', replies: [
      { id: 'r1', user: { name: '作者' }, time: '2025-01-01 11:00', content: '谢谢支持！' }
    ]},
    { id: 'c2', user: { name: '评论者B', avatar: '' }, time: '2025-01-02 09:00', likeCount: 1, content: '有些细节能再展开吗？', replies: []},
  ]});
}

export function postComment(articleId, payload) {
  // return request({ url: `/api/blog/${articleId}/comment`, method: 'post', data: payload });
  return Promise.resolve();
}

export function likeArticle(articleId) { return Promise.resolve(); }
export function favoriteArticle(articleId) { return Promise.resolve(); }

// 编辑器与发布
export function saveDraft(payload) { return Promise.resolve(); }
export function publishArticle(payload) { return Promise.resolve(); }

// 个人中心
export function fetchMyArticles() { return Promise.resolve({ data: { total: 3, items: [
  { id: 1, title: '我的文章1', status: '已发布', readCount: 120, likeCount: 12, commentCount: 3 },
  { id: 2, title: '我的文章2', status: '草稿', readCount: 0, likeCount: 0, commentCount: 0 },
  { id: 3, title: '我的文章3', status: '审核中', readCount: 10, likeCount: 1, commentCount: 0 },
]}}); }

export function fetchMyFavorites() { return Promise.resolve({ data: { total: 2, items: [
  { id: 101, title: '收藏文章A', author: '作者A', favoriteTime: '2025-01-03' },
  { id: 102, title: '收藏文章B', author: '作者B', favoriteTime: '2025-01-05' },
]}}); }

export function fetchMyLikes() { return Promise.resolve({ data: { total: 2, items: [
  { id: 'l1', type: '文章', title: '文章X', time: '2025-01-02' },
  { id: 'l2', type: '评论', title: '评论Y', time: '2025-01-04' },
]}}); }

export function fetchMyFollowings() { return Promise.resolve({ data: { items: [
  { id: 'u1', name: '用户1', intro: '算法爱好者' },
  { id: 'u2', name: '用户2', intro: '前端开发者' },
]}}); }

export function fetchMyFollowers() { return Promise.resolve({ data: { total: 1, items: [
  { id: 'u3', name: '用户3', intro: '后端工程师' },
]}}); }

export function fetchFeed() { return Promise.resolve({ data: { items: [
  { id: 'f1', user: '用户1', title: '新文章A', time: '今天' },
  { id: 'f2', user: '用户2', title: '新文章B', time: '本周' },
]}}); }

export function fetchDrafts() { return Promise.resolve({ data: { items: [
  { id: 'd1', title: '草稿1', updateTime: '2025-01-02' },
]}}); }

export function fetchNotifications() { return Promise.resolve({ data: { items: [
  { id: 'n1', type: '评论通知', content: '有人回复了你的评论', time: '2025-01-05' },
  { id: 'n2', type: '点赞通知', content: '你的文章获得了新点赞', time: '2025-01-06' },
]}}); }

export function fetchCommentManagement() { return Promise.resolve({ data: { items: [
  { id: 'c1', articleTitle: '我的文章1', user: '评论者A', content: '不错', time: '2025-01-03', likeCount: 2 },
]}}); }